home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Blender 2.49b / blender-2.49b-windows.exe / $_4_ / .blender / scripts / scripttemplate_pyconstraint.py < prev    next >
Text File  |  2009-08-31  |  4KB  |  115 lines

  1. #!BPY
  2. """
  3. Name: 'Script Constraint'
  4. Blender: 245
  5. Group: 'ScriptTemplate'
  6. Tooltip: 'Add a new script for custom constraints'
  7. """
  8.  
  9. from Blender import Window
  10. import bpy
  11.  
  12. script_data = \
  13. """#BPYCONSTRAINT
  14. '''
  15.     PyConstraint template, access this in the "add constraint" scripts submenu.
  16.     Add docstring here
  17. '''
  18.  
  19. import Blender
  20. from Blender import Draw
  21. from Blender import Mathutils
  22. import math
  23.  
  24. '''
  25.  This variable specifies the number of targets 
  26.  that this constraint can use
  27. '''
  28. NUM_TARGETS = 1
  29.  
  30.  
  31. '''
  32.  This function is called to evaluate the constraint
  33.     obmatrix:        (Matrix) copy of owner's 'ownerspace' matrix
  34.     targetmatrices:    (List) list of copies of the 'targetspace' matrices of the targets (where applicable)
  35.     idprop:            (IDProperties) wrapped data referring to this 
  36.                     constraint instance's idproperties
  37. '''
  38. def doConstraint(obmatrix, targetmatrices, idprop):
  39.     # Separate out the transformation components for easy access.
  40.     obloc = obmatrix.translationPart()    # Translation
  41.     obrot = obmatrix.toEuler()            # Rotation
  42.     obsca = obmatrix.scalePart()        # Scale
  43.  
  44.     # Define user-settable parameters
  45.     #     Must also be defined in getSettings().
  46.     if not idprop.has_key('user_toggle'): idprop['user_toggle'] = 1
  47.     if not idprop.has_key('user_slider'): idprop['user_slider'] = 1.0
  48.     
  49.     
  50.     # Do stuff here, changing obloc, obrot, and obsca.
  51.  
  52.     
  53.     # Convert back into a matrix for loc, scale, rotation,
  54.     mtxloc = Mathutils.TranslationMatrix(obloc)
  55.     mtxrot = obrot.toMatrix().resize4x4()
  56.     mtxsca = Mathutils.Matrix([obsca[0],0,0,0], [0,obsca[1],0,0], [0,0,obsca[2],0], [0,0,0,1])
  57.     
  58.     # Recombine the separate elements into a transform matrix.
  59.     outputmatrix = mtxsca * mtxrot * mtxloc
  60.  
  61.     # Return the new matrix.
  62.     return outputmatrix
  63.  
  64.  
  65.  
  66. '''
  67.  This function manipulates the matrix of a target prior to sending it to doConstraint()
  68.     target_object:                    wrapped data, representing the target object
  69.     subtarget_bone:                    wrapped data, representing the subtarget pose-bone/vertex-group (where applicable)
  70.     target_matrix:                    (Matrix) the transformation matrix of the target
  71.     id_properties_of_constraint:    (IDProperties) wrapped idproperties
  72. '''
  73. def doTarget(target_object, subtarget_bone, target_matrix, id_properties_of_constraint):
  74.     return target_matrix
  75.  
  76.  
  77. '''
  78.  This function draws a pupblock that lets the user set
  79.  the values of custom settings the constraint defines.
  80.  This function is called when the user presses the settings button.
  81.     idprop:    (IDProperties) wrapped data referring to this 
  82.             constraint instance's idproperties
  83. '''
  84. def getSettings(idprop):
  85.     # Define user-settable parameters.
  86.     # Must also be defined in getSettings().
  87.     if not idprop.has_key('user_toggle'): idprop['user_toggle'] = 1
  88.     if not idprop.has_key('user_slider'): idprop['user_slider'] = 1.0
  89.     
  90.     # create temporary vars for interface 
  91.     utoggle = Draw.Create(idprop['user_toggle'])
  92.     uslider = Draw.Create(idprop['user_slider'])
  93.     
  94.  
  95.     # define and draw pupblock
  96.     block = []
  97.     block.append("Buttons: ")
  98.     block.append(("Toggle", utoggle, "This is a toggle button."))
  99.     block.append("More buttons: ")
  100.     block.append(("Slider", uslider, 0.0000001, 1000.0, "This is a number field."))
  101.  
  102.     retval = Draw.PupBlock("Constraint Template", block)
  103.     
  104.     # update id-property values after user changes settings
  105.     if (retval):
  106.         idprop['user_toggle']= utoggle.val
  107.         idprop['user_slider']= uslider.val
  108.  
  109. """
  110.  
  111. new_text = bpy.data.texts.new('pyconstraint_template.py')
  112. new_text.write(script_data)
  113. bpy.data.texts.active = new_text
  114. Window.RedrawAll()
  115.